package com.mornd.gulimall.product.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;

import java.io.Serializable;
import java.util.List;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.mornd.gulimall.common.core.validation.UpdateGroup;
import lombok.Data;
import org.hibernate.validator.constraints.Range;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

/**
 * <p>
 * 商品三级分类
 * </p>
 *
 * @author mornd
 * @since 2023-07-23
 */
@Data
@TableName("pms_category")
public class Category implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 分类id
     */
    @NotNull(message = "分类id不能为空", groups = UpdateGroup.class)
    @TableId(value = "cat_id", type = IdType.AUTO)
    private Long catId;

    /**
     * 分类名称
     */
    @NotBlank(message = "分类名称不能为空")
    @Size(min = 0, max = 50, message = "分类名称长度不能超过50个字符")
    private String name;

    /**
     * 父分类id
     */
    @NotNull(message = "父分类id不能为空", groups = UpdateGroup.class)
    @Min(value = 0)
    private Long parentCid;

    /**
     * 层级
     */
    @Range(min = 1, max = 3, message = "层级不正确")
    @NotNull(message = "层级不能为空")
    private Integer catLevel;

    /**
     * 是否显示[0-不显示，1显示]
     */
    // ignore
    private Integer showStatus;

    /**
     * 排序
     */
    @NotNull
    private Integer sort;

    /**
     * 图标地址
     */
    private String icon;

    /**
     * 计量单位
     */
    private String productUnit;

    /**
     * 商品数量
     */
    @Min(value = 0)
    private Integer productCount;

    /**
     * 子分类
     */
    @JsonInclude(JsonInclude.Include.NON_EMPTY) // 数组长度为0，不解析
    @TableField(exist = false)
    List<Category> children;

}
